<%--
  Created by IntelliJ IDEA.
  User: bin.liu
  Date: 2018/12/12
  Time: 15:54
  To change this template use File | Settings | File Templates.
--%>
<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %>
<%@ taglib prefix="sec" uri="http://www.springframework.org/security/tags" %>
<jsp:include page="/pages/sysIndex/default.jsp"/>
<div class="main-content">
    <div class="box box-main">
        <div class="box-header">
            <div class="box-title">
                <i class="fa icon-trophy"></i> 资料管理
            </div>
            <div class="box-tools pull-right">
                <a href="#" class="btn btn-default" id="btnSearch" title="查询"><i class="fa fa-filter"></i> 查询</a>
                <sec:authorize access="hasRole('ROLE_ENTERPRISE_FACILITY_DATA_EDIT')">
                    <a href="javascript:;" onclick="vLayuiUtil.openLayerWindow('wFacilityData',
                            '<c:url value="/web/admin/facilityData/editPage.action"/>','新增',['80%', '95%'])"
                       class="btn btn-default btnTool" title="新增资料"><i class="fa fa-plus"></i> 新增</a>
                </sec:authorize>
            </div>
        </div>

        <div class="box-body">
            <form id="searchForm" action="<c:url value="/web/admin/facilityData/listJson.action"/>" method="post"
                  class="form-inline hide" data-page-no="1" data-page-size="20" data-order-by="">
                <div class="form-group">
                    <label class="control-label">资料名称：</label>
                    <div class="control-inline">
                        <input type="text" id="searchCode" name="searchCode" value="" maxlength="64"
                               class="form-control width-120">
                    </div>
                </div>

                <div class="form-group">
                    <label class="control-label">设备名称：</label>
                    <div class="control-inline">
                        <input type="text" id="facilityName" name="facilityName" value="" maxlength="64"
                               class="form-control width-120">
                    </div>
                </div>

                <div class="form-group">
                    <label class="control-label">资料分类：</label>
                    <div class="control-inline">
                        <input type="text" id="dataCatName" name="dataCatName" value="" maxlength="64"
                               class="form-control width-120">
                    </div>
                </div>

                <div class="form-group">
                    <button type="submit" class="btn btn-primary btn-sm">查询</button>
                    <button type="reset" class="btn btn-default btn-sm">重置</button>
                </div>
            </form>

            <div style="overflow-x:auto">
                <table id="dataGrid"></table>
            </div>
            <div id="dataGridPage"></div>
        </div>

    </div>
</div>
<script>
    $('#dataGrid').dataGrid({
        shrinkToFit:false,
        autoScroll: true,
        searchForm: $("#searchForm"),
        columnModel: [
            <sec:authorize access="hasRole('ROLE_ENTERPRISE_FACILITY_DATA_EDIT')">
            {
                header: '操作',
                name: 'actions',
                width: 180,
                sortable: false,
                title: false,
                align:"center",
                formatter: function (val, obj, row, act) {
                    var editUrl = '<c:url value="/web/admin/facilityData/editPage.action?id="/>' + row.id;
                    var result = '<a href="javascript:;" class="btn btn-default btn-xs btnList" onclick="vLayuiUtil.openLayerWindow(\'wFacilityData\', \'' + editUrl + '\',\'编辑\',[\'80%\', \'95%\'])"><i class="fa fa-pencil"></i> 编辑</a>&nbsp;';
                    result += '<a href="javascript:;" class="btn btn-default btn-xs btnList" title="预览" onclick="preview(\'' + row.id + '\')"><i class="fa fa-file-pdf-o"></i> 预览</a>&nbsp;';
                    result += '<a href="javascript:;" class="btn btn-default btn-xs btnList" title="删除" onclick="del(\'' + row.id + '\')"><i class="fa fa-trash-o"></i> 删除</a>&nbsp;';
                    return result;
                }
            },
            </sec:authorize>
            {header: '流水号', name: 'serialNum', index: 'serialNum', width: 155, align: "center"},
            {header: '资料名称', name: 'facilityDataName', index: 'facilityDataName', width: 200, align: "center"},
            {header: '描述', name: 'description', index: 'description', width: 280, align: "center"},
            {header: '关联设备', name: 'facilities', index: 'facility', width: 280, sortable:false, align: "center"},
            {header: '资料分类', name: 'dataCats', index: 'dataCat', width: 260, sortable:false, align: "center"},
            {header: '所属企业', name:'enterpriseName', index:'enterprise', width:160, align:"center"},
            {header: '上传时间', name: 'createDate', index: 'createDate', width: 150, align: "center"}
        ],
        // 加载成功后执行事件
        ajaxSuccess: function(data) {

        }
    });

    function preview(id) {
        vLayuiUtil.openLayerMaxWindow('wFacilityData', '<c:url
                        value="/web/admin/facilityData/previewFacilityDataFile.action?id="/>' + id ,'预览');
    }

    function del(id) {
        js.confirm('你确认要删除这条数据吗？',function () {
            $.ajax({
                type: 'POST',
                url: "<c:url value="/web/admin/facilityData/logicRemoveFacilityData.action"/>",
                data: {
                    id: id
                },
                dataType: 'json',
                async: false,
                error: function (data) {
                    js.showErrorMessage(data.responseText);
                },
                success: function (data, status, xhr) {
                    js.showMessage(data.msg);
                    if(data.status == Global.NO){
                        $('#dataGrid').dataGrid("refresh");
                    }
                }
            });
        });
    }

</script>